package ntd.block.port;

import cn.hutool.core.net.NetUtil;
import cn.hutool.core.thread.ThreadUtil;
import cn.hutool.log.StaticLog;

import java.util.ArrayList;
import java.util.List;

public class NtdPort {

    public static List<Integer> ports = new ArrayList<>();

    public static void main(String[] args) {
        listPort();
    }

    static {
        ThreadUtil.execAsync(() -> listPort());
    }

    /**
     * 已使用端口列表
     * @return
     */
    public static List<Integer> listPort() {
        ports = new ArrayList<>();
        for (int i = 0; i <= 65535; i++) {
            if (!NetUtil.isUsableLocalPort(i)) {
                ports.add(i);
            }
        }
        StaticLog.info("NTD ------ 已占用端口监测完成");
        return ports;
    }
}
